<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery-1.3.2.min.js"></script>
 
<style type="text/css">
	div{
		padding:8px;
	}
</style>
 

<script type="text/javascript">
     var counter = 0;
$(document).ready(function(){
 
     
      counter = <?php echo count($model1)+1; ?>;
      
    $("#addButton").click(function () {
 
	if(counter>10){
            alert("Only 10 textboxes allow");
            return false;
	}   
 
	var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
          
	newTextBoxDiv.html('<label>Enter Option '+ counter + ' : </label>' +
	      '<?php echo CHtml::activeTextArea($model1[0],"[]option"); ?>');
 
	newTextBoxDiv.appendTo("#TextBoxesGroup");
 
 
	counter++;
     });
 
     $("#removeButton").click(function () {
	if(counter==2){
          alert("No more textbox to remove");
          return false;
       }   
 
	counter--;
 
        $("#TextBoxDiv" + counter).remove();
 
     });
 
     $("#getButtonValue").click(function () {
 
	var msg = '';
	for(i=1; i<counter; i++){
   	  msg += "\n Option #" + i + " : " + $('#option').val();
	}
    	  alert(msg);
     });
  });
</script>


<?php echo CHtml::errorSummary(array($model)); 
echo CHtml::errorSummary($model1);
?>
<?php if(Yii::app()->user->hasFlash('success')){?>
  <div class="flash-success" style="color:black;background-color:#FFFF67;">
     <?php echo Yii::app()->user->getFlash('success');?></div>
<?php }?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'poll-option-form',
	'enableAjaxValidation'=>false,
)); ?>
<div>
		<label>Enter Question : </label><input type="text"  name='question' id='question' value="<?php echo $model->question;?>" >
</div>
<div id='TextBoxesGroup'>

<?php foreach($model1 as $key=>$optionmodel){?>
<div id="TextBoxDiv<?php echo $key+1;?>">
		<label>Enter Option <?php echo $key+1;?> : </label><?php echo CHtml::activeTextArea($optionmodel,"[]option"); ?>
	</div>
 <?php } ?>

</div><br/>
<input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>
<?php $this->endWidget(); ?>
